﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessObjects;
using System.Data;
using System.Data.OleDb;
using BusinessObjects;

namespace DataAccess.Access
{
    public class AccessChucVu: IChucVu
    {
        public ChucVu GetChucVu(int oid)
        {
            string sql = @"   SELECT MaQuanLy, TenChucVu 
                            FROM ChucVu 
                            Where Oid = @oid";

            OleDbParameter param = new OleDbParameter("@oid", oid);

            DataRow row = DataProvider.GetDataRow(sql, param);

            ChucVu chucVu = new ChucVu();
            chucVu.Oid = oid;
            chucVu.MaQuanLy = row["MaQuanLy"].ToString();
            chucVu.TenChucVu = row["TenChucVu"].ToString();

            return chucVu;
        }

        public List<ChucVu> GetListChucVu()
        {
            string sql = @" SELECT Oid, MaQuanLy, TenChucVu
                            FROM ChucVu";

            DataTable dt = DataProvider.GetDataTable(sql);

            List<ChucVu> list = new List<ChucVu>();

            foreach (DataRow row in dt.Rows)
            {
                ChucVu chucVu = new ChucVu();

                chucVu.Oid = int.Parse(row["Oid"].ToString());
                chucVu.MaQuanLy = row["MaQuanLy"].ToString();
                chucVu.TenChucVu = row["TenChucVu"].ToString();

                list.Add(chucVu);
            }

            return list;
        }

        public int Insert(ChucVu obj)
        {
            string sql = @" Insert into ChucVu(MaQuanLy, TenChucVu)
                            Values(@MaQuanLy, @TenChucVu)";
            OleDbParameter[] param = {
                                       new OleDbParameter("@MaQuanLy", obj.MaQuanLy),
                                       new OleDbParameter("TenChucVu", obj.TenChucVu)
                                   };
            DataProvider.Insert(sql, param);
            return 0;
        }

        public int Update(ChucVu obj)
        {
            throw new NotImplementedException();
        }

        public int Delete(ChucVu obj)
        {
            throw new NotImplementedException();
        }


        public int Save(ChucVu obj)
        {
            throw new NotImplementedException();
        }
    }
}
